function [s_hat,signal] = gen_ortho_detector_qamsixteen(h,r,rho,nt,nr)

for m=0:15
	int_rep=int2bin(m);
	s_possible(m+1)=bin2qamsixteen(int_rep(5:8));
end

sum2=0;
for k=1:nr
	for z=1:4
		sum2=sum2+ abs(h(k,z)).^2;
	end
end


sum1=r(1,1)*conj(h(1,1)) + r(1,2)*conj(h(1,2)) + r(1,3)*conj(h(1,3)) + r(1,4)*conj(h(1,4)) + conj(r(1,5))*h(1,1) + conj(r(1,6))*h(1,2) + conj(r(1,7))*h(1,3) + conj(r(1,8))*h(1,4);
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + 2*sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(1)=s_possible(index);

sum1=r(1,1)*conj(h(1,2)) - r(1,2)*conj(h(1,1)) - r(1,3)*conj(h(1,4)) + r(1,4)*conj(h(1,3)) + conj(r(1,5))*h(1,2) - conj(r(1,6))*h(1,1) - conj(r(1,7))*h(1,4) + conj(r(1,8))*h(1,3);
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + 2*sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(2)=s_possible(index);

sum1=r(1,1)*conj(h(1,3)) + r(1,2)*conj(h(1,4)) - r(1,3)*conj(h(1,1)) - r(1,4)*conj(h(1,2)) + conj(r(1,5))*h(1,3) + conj(r(1,6))*h(1,4) - conj(r(1,7))*h(1,1) - conj(r(1,8))*h(1,2);
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + 2*sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(3)=s_possible(index);


sum1=-r(1,1)*conj(h(1,4)) - r(1,2)*conj(h(1,3)) + r(1,3)*conj(h(1,2)) - r(1,4)*conj(h(1,1)) - conj(r(1,5))*h(1,4) - conj(r(1,6))*h(1,3) + conj(r(1,7))*h(1,2) - conj(r(1,8))*h(1,1);
sum1=sum1*sqrt(nt/rho);
sum=(abs(sum1-s_possible)).^2 + (-1 + 2*sum2)*(abs(s_possible).^2);
[minim,index]=min(sum);
s_hat(4)=s_possible(index);




signal=[];
for m=1:length(s_hat)
	signal=horzcat(signal,qamsixteen2bin(s_hat(m)));
end
